﻿using SnmpForm.SnmpWrapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SnmpForm.BusinessWrapper
{
    public class Ap:SnmpWrapper.ApSnmp
    {
        DbWrapper.DbDataTypes.Ap m_apInfo=null;
        DbWrapper.DbDataTypes.WirelessInfo m_infoWireless = null;
        DbWrapper.DbDataTypes.WirelessSecurity m_infoWirelessSecurity = null;
        DbWrapper.DbDataTypes.Dhcp m_infoDhcpConfig = null;
        DbWrapper.DbDataTypes.Advance_tools m_infoAdvanceTools = null;
        public string m_strSysRunningTime = "";
        public int m_nNumOnAp = 0;
        public Ap(DbWrapper.DbDataTypes.Ap ap):base(ap)
        {
            m_apInfo = ap;
        }
        public DbWrapper.DbDataTypes.Ap GetInfo()
        {
            return m_apInfo;
        }

        public DbWrapper.DbDataTypes.WirelessInfo GetApWireless(bool bFromDb = false)
        {
            if (m_infoWireless == null || bFromDb)
            {
                m_infoWireless =
                    DbWrapper.SQLDataOperate.Instance.GetWirelessInfo(m_apInfo.id);
                //如果数据库中不存在无线信息，自动创建
                if (m_infoWireless == null)
                {
                    m_infoWireless = new DbWrapper.DbDataTypes.WirelessInfo();
                    m_infoWireless.apid = m_apInfo.id;
                    bool bCreateWirelessInfo = DbWrapper.SQLDataOperate.Instance.SetWirelessInfo(
                        User.Instance.GetCurrentUserInfo().id,
                        m_infoWireless);
                    if (!bCreateWirelessInfo)
                    {
                        throw new Exception("创建AP无线信息记录错误");
                    }
                }
            }
            return m_infoWireless;
        }

        public DbWrapper.DbDataTypes.WirelessSecurity GetWirelessSecurity(bool bFromDb = false)
        {
            if (m_infoWirelessSecurity == null || bFromDb)
            {
                m_infoWirelessSecurity = 
                    DbWrapper.SQLDataOperate.Instance.GetWirelessSecurity(m_apInfo.id);
                if (m_infoWirelessSecurity == null)
                {
                    //自动创建无线安全信息记录
                    m_infoWirelessSecurity = new DbWrapper.DbDataTypes.WirelessSecurity();
                    m_infoWirelessSecurity.apid = m_apInfo.id;
                    bool bCreateWirelessSecurityInfo = DbWrapper.SQLDataOperate.Instance.SetWirelessSecurity(
                        User.Instance.GetCurrentUserInfo().id,
                        m_infoWirelessSecurity);
                    if (!bCreateWirelessSecurityInfo)
                    {
                        throw new Exception("创建AP无线安全信息记录错误");
                    }
                }
            }
            return m_infoWirelessSecurity;
        }

        public DbWrapper.DbDataTypes.Advance_tools GetAdvanceTools(bool bFromDb = false)
        {
            if (m_infoAdvanceTools == null || bFromDb)
            {
                m_infoAdvanceTools =
                    DbWrapper.SQLDataOperate.Instance.GetAdvanceTools(
                        User.Instance.GetCurrentUserInfo().id, 
                        m_apInfo.id);
                if (m_infoAdvanceTools == null)
                {
                    //自动创建无线安全信息记录
                    m_infoAdvanceTools = new DbWrapper.DbDataTypes.Advance_tools();
                    m_infoAdvanceTools.apid = m_apInfo.id;
                    bool bCreateAdvanceToolsInfo = DbWrapper.SQLDataOperate.Instance.SetAdvanceTools(
                        User.Instance.GetCurrentUserInfo().id,
                        m_infoAdvanceTools);
                    if (!bCreateAdvanceToolsInfo)
                    {
                        throw new Exception("创建AP高级信息记录错误");
                    }
                }
            }
            return m_infoAdvanceTools;
        }

        public bool ScanApAllInfo()
        {
            ScanApInfo();
            ScanWirelessInfo();
            ScanWirelessSecurity();
            ScanAdvanceTools();


            string strRunningTime = ScanSystemRunningTime();
            strRunningTime = strRunningTime.Replace("d", "天");
            strRunningTime = strRunningTime.Replace("h", "小时");
            strRunningTime = strRunningTime.Replace("m", "分钟");
            strRunningTime = strRunningTime.Replace("s", "秒");
            m_strSysRunningTime = strRunningTime;

            m_nNumOnAp = ScanNumOfstaOnAp();

            return true;
        }

        public bool ScanApInfo()
        {
            DbWrapper.DbDataTypes.Ap apinfo =
                    GetInfo();

            try
            {
                apinfo.software = ScanSoftwareVersion();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message, 
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try{
                apinfo.hardware = ScanHardVersion();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                apinfo.landhcp = ScanLanDhcp();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try{
                apinfo.ip = ScanLanIp();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try{
                apinfo.netmask = ScanLanNetmask();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                apinfo.gateway = ScanLanGateway();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            return true;
        }

        public bool ScanWirelessInfo()
        {
            DbWrapper.DbDataTypes.WirelessInfo infoWireless =
                GetApWireless();

            try
            {
                infoWireless.workmode = ScanApWorkMode();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                ScanApIpAddr();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            try
            {
                infoWireless.mac = ScanApMacAddr();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                infoWireless.ssid = ScanApSSID();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                infoWireless.channel = ScanApPrimaryChannal();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                infoWireless.wirelessmode = ScanWirelessMode();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                infoWireless.enable = ScanWirelessOnBoot();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            try
            {
                infoWireless.wds = ScanWDS();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                infoWireless.power = ScanTxPower();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            try
            {
                infoWireless.wmm = ScanWMM();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            try
            {
                infoWireless.short_gi = ScanShortGI();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }

            return true;
        }

        public bool ScanWirelessSecurity()
        {
            DbWrapper.DbDataTypes.WirelessSecurity info =
                        GetWirelessSecurity();

            string strWirelessSecureStat = "";
            try
            {
                strWirelessSecureStat =
                    ScanWirelessSecureStat();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
                return false;
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
                return false;
            }
            //          字符串的顺序依次是（中间用#隔开）
            //--->无线安全状态(WPA)#认证类型(自动:3 WPA-PSK:1 WPA2-PSK:3)#加密算法(自动:TKIP CCMP、AES:CCMP、TKIP:TKIP)#PSK密码
            //--->无线安全状态(WEP)#认证类型(自动:4 开放系统:1 共享密钥:3)#WEP密钥格式(十六进制:0、ASCLL码:1)%密钥选择(1、2、3、4)#WEP密钥#密钥类型:(64位:64、128位:128、152位:152)
            //--->无线安全状态(None)
            string[] args = strWirelessSecureStat.Split('#');
            if (args != null)
            {
                if (args.Length > 0)
                {
                    info.secmode = args[0];
                    switch (info.secmode)
                    {
                        case "None":
                            break;
                        case "WPA":
                            info.wpa_mode = Convert.ToInt16(args[1]);
                            info.wpa_cypher = args[2];
                            info.psk_key = args[3];
                            break;
                        case "WEP":
                            info.wep_mode = Convert.ToInt16(args[1]);
                            info.wep_passwd_pattern = Convert.ToInt16(args[2]);
                            //密钥选择
                            info.wep_key_index = Convert.ToInt32(args[3]);
                            int nIndex = info.wep_key_index - 1;
                            info.wep_key[nIndex].passwd_mode = 
                                Convert.ToInt32(args[4]);
                            info.wep_key[nIndex].key = args[5];

                            break;
                        default:
                            break;
                    }
                }
            }

            info.wpa_group_rekey = ScanGroupKeyUpdateCycle();
            
            return true;
        }
        public DbWrapper.DbDataTypes.Dhcp GetDhcpConfig(bool bFromDb = false)
        {
            if (m_infoDhcpConfig == null || bFromDb)
            {
                m_infoDhcpConfig =
                    DbWrapper.SQLDataOperate.Instance.GetApDhcp(User.Instance.GetCurrentUserInfo().id, 
                        m_apInfo.id);
                if (m_infoDhcpConfig == null)
                {
                    //自动创建DHCP配置记录
                    m_infoDhcpConfig = new DbWrapper.DbDataTypes.Dhcp();
                    m_infoDhcpConfig.apid = m_apInfo.id;
                    m_infoDhcpConfig.addressLease = 120;
                    bool bCreateDhcpInfo = DbWrapper.SQLDataOperate.Instance.SetDhcp(
                        User.Instance.GetCurrentUserInfo().id,
                        m_infoDhcpConfig);
                    if (!bCreateDhcpInfo)
                    {
                        throw new Exception("创建AP DHCP记录错误");
                    }
                }
            }
            return m_infoDhcpConfig;
        }

        public bool ScanAdvanceTools()
        {
            DbWrapper.DbDataTypes.Advance_tools infoAdvanceTools =
                GetAdvanceTools();
            try
            {
                infoAdvanceTools.led_light = ScanLedLight();
            }
            catch (Lextm.SharpSnmpLib.Messaging.ErrorException ex)
            {
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            catch (SnmpNullException ex)
            {
                //MessageBox.Show("代理程序没有提供接口" + ex.Message);
                DbWrapper.SQLDataOperate.Instance.WriteMessage(
                    DbWrapper.DbDataTypes.LogInfo.LEVEL.ERROR,
                    DbWrapper.DbDataTypes.LogInfo.TYPE.SYSTEM,
                    ex.Message,
                    DbWrapper.DbDataTypes.User.UNKNOW);
            }
            return true;
        }
    }
}
